package com.example.mobile2021606134chhnewdemo.NewsModule;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mobile2021606134chhnewdemo.R;

import java.util.ArrayList;
import java.util.List;

public class NewContentActivity extends AppCompatActivity {

    private RecyclerView rvNewContent;
    private List<News> list = new ArrayList<>();
    private TextView tvNewContentTitle;
    private TextView tvNewContentSrc;

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity_new_content);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.item_new_content_bar);
        initTitleBar();
        initView();

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        String title = bundle.getString("title");
        String time = bundle.getString("time");
        String src = bundle.getString("src");
        String category = bundle.getString("category");
        String pic = bundle.getString("pic");
        String content = bundle.getString("content");
        String url = bundle.getString("url");
        String WebUrl = bundle.getString("WebUrl");
        list.add(new News(title, time, src, category, pic, content, url, WebUrl));
        String msrc = time;

        tvNewContentTitle.setText(title);
        tvNewContentSrc.setText("来源：" + msrc);
        rvNewContent.setLayoutManager(new LinearLayoutManager(this));
        rvNewContent.setAdapter(new NewContentRViewAdapter(list, this));
        rvNewContent.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                findViewById(R.id.childScroll).getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        });

    }

    private void initTitleBar() {
        View viewNewContentBack = findViewById(R.id.viewNewContentBack);
        View viewNewContentShare = findViewById(R.id.viewNewContentShare);
        View viewNewContentMore = findViewById(R.id.viewNewContentMore);
        viewNewContentBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        viewNewContentShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        viewNewContentMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    private void initView() {
        rvNewContent = (RecyclerView) findViewById(R.id.rvNewContent);
        rvNewContent.setHasFixedSize(true);
        rvNewContent.setNestedScrollingEnabled(false);
        tvNewContentTitle = (TextView) findViewById(R.id.tvNewContentTitle);
        tvNewContentSrc = (TextView) findViewById(R.id.tvNewContentSrc);
    }
}